const corpIdStr = "ding347b4c4d0e79330a4ac5d6980864d335";
var codeStr = '';

function getClockList(url, userName) {
    if(url!=null && url!== '') {
        location.replace(url + "?userName=" + userName);
    }
    // location.replace("/attend/getClockList?userName=" + userName);
    // location.href = "/app/getClockList?userName=" + userName;
}

function login(url) {
    $.ajax({
        url: "/dingTalk/login?code=" + codeStr,
        data: {},
        type: "get",
        dataType: "json",
        success: function (resp) {
            var userData = resp;
            localStorage.setItem('userData', JSON.stringify(userData));
            getClockList(url,userData.userName);
        },
        timeout: 50000,
        error: function (xhr, textStatus, errorThrown) {
            alert("系统异常，请联系管理员");
        }
    });
}
// 检查获取登录，并跳转相应页面
function checkLogin(successUrl) {
    let item = localStorage.getItem('userData');
    item = JSON.parse(item);
    if (item == null) {
        dd.getAuthCode({
            corpId: corpIdStr,
            success: (res) => {
                const { code } = res;
                codeStr = code;
                login(successUrl);
            },
            fail: () => {
            },
            complete: () => {
            },
        });
        // codeStr = "f6010f2957913082bd8fb56ec63ea34f";
        // login(successUrl);
    } else {
        getClockList(successUrl,item.userName);
    }
}
function getUserInfo() {
    let item = localStorage.getItem('userData');
    item = JSON.parse(item);
    return item;
}
